﻿var InitPostUrl = "../Handler/AdminHandler.ashx";
var YXQ = {
    Manager: {},
    Common: {}
}
YXQ.Common = {
    SelAll: function () {
        $("input:checkbox").each(function (i) {
             this.checked = true; 

        });

    },
    NoSelAll: function () {
        $("input:checkbox").each(function (i) {
            this.checked = false;
        });
    },
    ConvertCH: function (title, control) {

        XTCore.Form.PostData(
               InitPostUrl,
                { OpType: "GetPY", PostData: title },
                function (e) {

                    $("[" + control + "]").val(e.ResultMessage);

                });

    },
    GetCheckboxItem: function () {
        var allSel = "";
        $("input:checkbox").each(function (i) {
            if (this.checked) {
                allSel += this.value + ",";
            }
        });
        return allSel.substring(0, allSel.length - 1);

    },
    GetOneItem: function () {
        var allSel = "";
        $("input:checkbox").each(function (i) {
            if (allSel == "") {
                allSel = this.value;
            }
        });

    },
    DelOneById: function (optype, id, rtnUrl) {
        XTCore.Form.PostData(
            InitPostUrl,
            { OpType: optype, PostData: id },
            function (e) {
                if (e.ResultMessage == "Success") {
                    XT.Common.Message("成功删除！");
                    window.location.href = "../manager/" + rtnUrl;
                }
            });
    },
    CheckNull: function (ctrol, message) {
        if ($("[Datafield=" + ctrol + "]").length > 0) {
            if ($("[Datafield=" + ctrol + "]").val() == "") {
                XT.Common.Message(message);
                return false;
            }
        } else if ($("#" + ctrol).val() == "") {
            XT.Common.Message(message);
            return false;
        }

    },
    Message: function (head,msg) {
        $.messager.alert(head, msg);
        return;
    }
};

YXQ.Manager = {
    Login: function () {
        var uname = $("#username").val();
        var password = $("#password").val();
        
        if (uname == "") {
            XT.Common.Message("对不起请输入用户名！");
            return;
        }
        if (password == "") {
            XT.Common.Message("对不起请输入密码！");
            return;
        }

        YXQCore.Form.PostData(
        InitPostUrl,
        { OpType: "ChkLogin", PostData: uname, strValue: password},
        function (e) {
            window.location.href = "manager/index.aspx";
            if (e.ResultMessage == "LoginFailed") {
                XT.Common.Message("对不起，用户名或密码错误！");
                return;
            } else if (e.ResultMessage == "SessionCodeFailed") {
                XT.Common.Message("对不起，验证码输入有误！");
                return;
            }  else if (e.ResultMessage == "Success") {
                window.location.href = "manager/index.aspx";
            }
        });

    } 
}